package com.mall.manager.abilitystatic.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@SuppressWarnings({"rawtypes","unchecked"})
@Service
public class AbilityService {

	private Logger logger = LoggerFactory.getLogger(AbilityService.class);
	
	@Resource(name="jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	 
	/**
	 * 查询八大能力平均分
	 * @param request
	 * @return
	 */
	public List findAbility(HttpServletRequest request){
		 try{
			//如果是第一次加载地图，按省级（包括直辖市）查询园所数量
		    	String sqlp = "select * from db_archive.province";
		    	List list = jdbcTemplate.queryForList(sqlp);
		    	StringBuffer codes = new StringBuffer("'");
		    	JSONArray ar = JSONArray.fromObject(list);
		    	for(int i=0;i<ar.size();i++){
		    		Map<String,Object> map = JSONObject.fromObject(ar.get(i));
		    		codes.append(MapUtils.getString(map, "code")).append("','");
		    	} 
		    	StringBuffer sbf = new StringBuffer("select * from db_processing.t_ability_statistics as a where 1=1");
	    		String cd = codes.toString().substring(0, codes.toString().length()-2);
	    		sbf.append(" and a.area_id in(").append(cd).append(")");
	    		return this.jdbcTemplate.queryForList(sbf.toString());
		 }catch(Exception e){
			 logger.info("查询八大能力平均分数据出现异常："+e.getMessage());
		 }
		 return null;
	 }
}
